//
//  WorkflowSelectUserCell.m
//  RSW.IOS
//
//  Created by zhaiqiuqiu on 2017/9/4.
//  Copyright © 2017年 com.xtion.crm. All rights reserved.
//

#import "WorkflowSelectUserCell.h"

@interface WorkflowSelectUserCell()
{
    UILabel *_titleLabel; 
    
    UIImageView *_arrowImageView;
    
    CGFloat _left;
    
    HeadImageView *_headImageView;
}
@end

@implementation WorkflowSelectUserCell

-(id)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithReuseIdentifier:reuseIdentifier];
    self.backgroundColor = [UIColor colorWithHex:mcrmSAASUISkinColorTextStylef1f4f7Color];
    
    _left = 12.5;
    
    _headImageView = [[HeadImageView alloc]initWithFrame:CGRectMake(0,0, 45, 45)];
    _headImageView.headImage = [UIImage imageNamed:@"img_defaulthead.png"];
    _headImageView.layer.cornerRadius = 22.5;
    _headImageView.clipsToBounds = YES;
    
    _headImageView.hidden = YES;
    
    [self.contentView addSubview:_headImageView];
    
    CGSize size = [NSString charSizeWithFont:[UIFont systemFontOfSize:13]];
    _titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, size.width * 6, size.height)];
    _titleLabel.backgroundColor = [UIColor clearColor];
    _titleLabel.textColor = [UIColor blackColor];
    _titleLabel.font = [UIFont systemFontOfSize:13];
    _titleLabel.textAlignment = NSTextAlignmentLeft;
    [self addSubview:_titleLabel];
    
    _arrowImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"img_arrowup"]];
    [self addSubview:_arrowImageView];
    
    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];

    _headImageView.left = 12.5;
    _headImageView.centerY = self.contentView.height/2; 
    _headImageView.headImage = [UIImage getImage:[_titleLabel.text substringToIndex:1]];
    
    _titleLabel.left = _left;
    _titleLabel.centerY = self.contentView.height/2;
    _titleLabel.width = self.contentView.width - _left - 12.5 - _arrowImageView.width - 10;
    
    _arrowImageView.right = self.width - 10;
    _arrowImageView.centerY = self.height/2;
}

-(void)setTitle:(NSString *)title
{
    _titleLabel.text = title;
}

-(void)setArrowImage:(NSString *)arrowImage
{
    _arrowImageView.image = [UIImage imageNamed:arrowImage];
}

-(void)setTitleLeftLevel:(NSInteger)level
{
    _arrowImageView.hidden = NO;
    if(level == 0)
    {
        _left = 12.5;
    }
    else if(level == 1)
    {
        _left = 12.5*3;
    }
    else if(level == 2)
    {
        _left = 12.5*4;
    }
    else if(level == 3)
    {
        _left = 12.5*5;
        _arrowImageView.hidden = YES;
        _headImageView.hidden = NO;
    }
}

+(CGFloat)caleHeight
{
    return 50;
}

@end
